﻿//  Copyright (c) 2011 Ray Liang (http://www.dotnetage.com)
//  Licensed MIT: http://www.opensource.org/licenses/mit-license.php

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace DNA.Mvc.Community
{
    public class ThreadWrapper : Thread
    {
        private Thread innerThread;

        public ThreadWrapper(Thread thread)
        {
            innerThread = thread;
        }

        #region Overrides

        public override int ID
        {
            get
            {
                return innerThread.ID;
            }
            set
            {
                innerThread.ID = value;
            }
        }

        public override bool IsDeleted
        {
            get
            {
                return innerThread.IsDeleted;
            }
            set
            {
                innerThread.IsDeleted = value;
            }
        }

        public override DateTime Approved
        {
            get
            {
                return innerThread.Approved;
            }
            set
            {
                if (innerThread != null)
                    innerThread.Approved = value;
            }
        }

        public override string Author
        {
            get
            {
                return innerThread.Author;
            }
            set
            {
                innerThread.Author = value;
            }
        }

        public override int TotalReads
        {
            get
            {
                return innerThread.TotalReads;
            }
            set
            {
                innerThread.TotalReads = value;
            }
        }

        public override bool IsQuestion
        {
            get
            {
                return innerThread.IsQuestion;
            }
            set
            {
                innerThread.IsQuestion = value;
            }
        }

        public override string LastPostUser
        {
            get
            {
                return innerThread.LastPostUser;
            }
            set
            {
                innerThread.LastPostUser = value;
            }
        }

        public override string LinkTo
        {
            get
            {
                return innerThread.LinkTo;
            }
            set
            {
                innerThread.LinkTo = value;
            }
        }

        public override int TotalPosts
        {
            get
            {
                return innerThread.TotalPosts;
            }
            set
            {
                innerThread.TotalPosts = value;
            }
        }

        public override string Title
        {
            get
            {
                return innerThread.Title;
            }
            set
            {
                innerThread.Title = value;
            }
        }

        public override int ThreadType
        {
            get
            {
                return innerThread.ThreadType;
            }
            set
            {
                innerThread.ThreadType = value;
            }
        }

        public override ICollection<Post> Posts
        {
            get
            {
                return innerThread.Posts;
            }
            set
            {
                innerThread.Posts = value;
            }
        }

        public override DateTime Posted
        {
            get
            {
                return innerThread.Posted;
            }
            set
            {
                innerThread.Posted = value;
            }
        }

        public override string Moderator
        {
            get
            {
                return innerThread.Moderator;
            }
            set
            {
                innerThread.Moderator = value;
            }
        }

        public override int? LastPostID
        {
            get
            {
                return innerThread.LastPostID;
            }
            set
            {
                innerThread.LastPostID = value;
            }
        }

        public override DateTime LastPosted
        {
            get
            {
                return innerThread.LastPosted;
            }
            set
            {
                innerThread.LastPosted = value;
            }
        }

        public override bool IsResolved
        {
            get
            {
                return innerThread.IsResolved;
            }
            set
            {
                innerThread.IsResolved = value;
            }
        }

        public override bool IsPinned
        {
            get
            {
                return innerThread.IsPinned;
            }
            set
            {
                innerThread.IsPinned = value;
            }
        }

        public override bool IsLocked
        {
            get
            {
                return innerThread.IsLocked;
            }
            set
            {
                innerThread.IsLocked = value;
            }
        }

        public override bool IsApproved
        {
            get
            {
                return innerThread.IsApproved;
            }
            set
            {
                innerThread.IsApproved = value;
            }
        }

        public override int ForumID
        {
            get
            {
                return innerThread.ForumID;
            }
            set
            {
                innerThread.ForumID = value;
            }
        }

        public override DNA.Mvc.Community.Forum Forum
        {
            get
            {
                return innerThread.Forum;
            }
            set
            {
                innerThread.Forum = value;
            }
        }

        #endregion

        public bool IsModerator(HttpContextBase httpContext)
        {
            if (httpContext.Request.IsAuthenticated)
            {
                if (HttpContext.Current.User.IsInRole("administrators"))
                    return true;
                return Forum.Moderators.FirstOrDefault(m => m.UserName.Equals(httpContext.User.Identity.Name)) != null;
            }
            return false;
        }
    }
}
